package cn.wolfcode.car.service.impl;

import cn.wolfcode.car.domain.Role;
import cn.wolfcode.car.mapper.RoleMapper;
import cn.wolfcode.car.qo.RoleQueryObject;
import cn.wolfcode.car.service.IRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int delete(Long id) {
        return roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int save(Role record) {
        return roleMapper.insert(record);
    }

    @Override
    public Role get(Long id) {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Role> list(RoleQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Role> list = roleMapper.selectForPage(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<Role> listAll() {
        return roleMapper.selectAll();
    }

    @Override
    public int update(Role record) {
        return roleMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Role> listByEmployeeId(Long id) {
        return roleMapper.selectByEmployeeId(id);
    }

    @Override
    public List<String> selectSnByEmployeeId(Long id) {
        return roleMapper.selectSnByEmployeeId(id);

    }
}
